package Demo06.Demo02;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Demo06_NIO {
    public static void main(String[] args) throws IOException {
        String ad ="G:\\XQ1.01\\a.txt";
        String ap ="G:\\css3\\c.txt";
        FileInputStream fis = new FileInputStream(ad);
                            //获得的通道将允许进行读取操作
        FileChannel ch = fis.getChannel();

        FileOutputStream fos = new FileOutputStream(ap);
        FileChannel ca = fos.getChannel();
                                        // ByteBuffer.allocat:分配一个新的字节缓冲区。
        ByteBuffer allocate = ByteBuffer.allocate(512);

        while (ch.read(allocate)!=-1){
            allocate.flip();
            ca.write(allocate);

            allocate.flip();
        }

    }
}
